﻿using System;
using System.Data;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Content;

namespace RickDnn.Modules.DNNTaskManager.Components
{
    public class Task:ContentItem
    {        
        public int TaskId  { get; set; }       
        public string TaskName { get; set; }      
        public string TaskDescription { get; set; }        
        public int AssignedUserId { get; set; }       
        public int ModuleId { get; set; }        
        public DateTime? TargetCompletionDate { get; set; }        
        public DateTime? CompletedOnDate { get; set; }
        //base member
        //public int ContentItemId { get; set; }      
        public DateTime CreatedOnDate { get; set; }
        public int CreatedByUserId { get; set; }        
        public DateTime LastModifiedOnDate { get; set; }       
        public int LastModifiedByUserId { get; set; }
        
        
        //Add more properties than sql
        //portal where the artical resides
        public int PortalId { get; set; }
        public string CreatedByUser {
            get
            {
                return CreatedByUserId != 0 ? DotNetNuke.Entities.Users.UserController.GetUserById(PortalId, CreatedByUserId).Username : Null.NullString;
            }
        }
        public string LastUpdateByUser {
            get
            {
                return LastModifiedByUserId != 0 ? DotNetNuke.Entities.Users.UserController.GetUserById(PortalId, LastModifiedByUserId).Username : Null.NullString;
            }           
        }
        #region IHyDratable Implementation
        public override void Fill(IDataReader dr)
        {
            //call base class fill method to populate the base class properties
            base.Fill(dr);
            TaskId=Null.SetNullInteger(dr["TaskId"]);
            TaskName = Null.SetNullString(dr["TaskName"]);       
            TaskDescription = Null.SetNullString(dr["TaskDescription"]);      
            AssignedUserId=Null.SetNullInteger(dr["AssignedUserId"]);       
            ModuleId=Null.SetNullInteger(dr["ModuleId"]);            
            TargetCompletionDate = Null.SetNullDateTime(dr["TargetCompletionDate"]);
            CompletedOnDate = Null.SetNullDateTime(dr["CompletedOnDate"]);
           
            //base member
            //public int ContentItemId { get; set; }                  
            CreatedOnDate = Null.SetNullDateTime(dr["CreatedOnDate"]);       
            CreatedByUserId=Null.SetNullInteger(dr["CreatedByUserId"]);        
            LastModifiedOnDate = Null.SetNullDateTime(dr["LastModifiedOnDate"]);         
            LastModifiedByUserId=Null.SetNullInteger(dr["LastModifiedByUserId"]);    
        }
        public override int KeyID
        {
            get {   //return base.KeyID;
                    return TaskId;
               }

            set { //base.KeyID = value;
                   TaskId = value;
                }
        }
        #endregion
    }
}